package com.aegis.manage.controller.gateway;

import com.aegis.common.mybatis.model.PageResult;
import com.aegis.core.model.AegisUserApi;
import com.aegis.core.model.AegisAppGroupPermission;
import com.aegis.manage.api.request.QueryUserInfoPageRequest;
import com.aegis.manage.api.vo.AuthUserInfoVO;
import com.aegis.manage.service.auth.user.UserPermissionService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wuweixin
 *
 * @Version 1.0
 * @Descritube
 */
@RestController
@RequestMapping("/gateway/appUser")
@Api(tags = "网关-应用用户管理")
public class GatewayUserManageController {


    @Autowired
    private UserPermissionService userPermissionService;


    /**
     * 查询应用的用户权限组
     * @param id 应用id
     * @return
     */
    @GetMapping("/permissionGroup/list")
    public List<AegisAppGroupPermission> queryUserGroupPermission(@RequestParam String id) {
        return userPermissionService.queryUserGroupPermission(id);
    }

    /**
     * 查询应用的用户权限组有哪些api
     * @param id 应用id
     * @param groupKey 权限组key
     * @return
     */
    @GetMapping("/permissionGroup/api/list")
    public List<AegisUserApi> queryUserGroupApi(@RequestParam String id, @RequestParam String groupKey) {
        return userPermissionService.queryUserGroupApi(id, groupKey);
    }

    /**
     * 查询应用下有多少登录的用户
     * @param request
     * @return
     */
    @GetMapping("/page")
    public PageResult<AuthUserInfoVO> queryUserInfoPage(@Validated QueryUserInfoPageRequest request) {
        return userPermissionService.queryUserInfoPage(request);
    }

}
